package com.jwx.controller;


import com.jwx.pojo.Category;
import com.jwx.pojo.Result;
import com.jwx.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    @PostMapping
    public Result add(@RequestBody Category category){
        categoryService.add(category);
        return Result.success();
    }
    @GetMapping
    public Result List<Category> list()
    {
       List<Category> cs= categoryService.list();
       return Result.success(cs);
    }
    @GetMapping("/detail")
    public Result<Category> detail(Integer id){
       Category c= categoryService.findById(id);
       return Result.success(c);
    }
@PutMapping
    public Result update(@RequestBody @Validated Category category){
        categoryService.update(category);
        return  Result.success();
    }


}
